<template>
  <div class="newpeople">
    <!-- 人员设置 form -->
    <!-- <el-row :gutter="24" class="form" id="formt" style="background:#fff; position: relative;">
      <el-col :span="7">
        <div class="grid-content">
          <el-form :model="searchForm" label-width="95px" @submit.native.prevent class="demo-form">
            <el-form-item label="场所名称" class="img-name">
              <el-input
                v-model="searchForm.siteName"
                placeholder="请输入场所名称"
                style="width: 280px;"
                clearable
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="15" class="btn-cx">
        <div class="grid-content">
          <el-form
            :model="searchForm"
            label-width="100px"
            @submit.native.prevent
            style="float: right"
          >
            <el-button type="primary" @click="search" class="search-btn">查询</el-button>
          </el-form>
        </div>
      </el-col>
    </el-row> -->
    <!-- 人员列表 -->
    <div class="poeple-list">
      <el-table :data="listData" stripe :header-cell-style="getRowClass" v-loading="loading">
        <el-table-column prop="num" label="序号"></el-table-column>
        <el-table-column prop="site_name" label="场所名称"></el-table-column>
        <el-table-column prop="areaName" label="区域名称"></el-table-column>
        <el-table-column prop="address" label="详细地址"></el-table-column>
        <el-table-column prop="create_time" label="删除时间"></el-table-column>
      </el-table>
      <page-list
        :size.sync="pageSize"
        :total="totals"
        :current.sync="currentPage"
        @change="getPeople"
      ></page-list>
    </div>
  </div>
</template>

<script>
import Config from "../../../config";
import moment from "moment";
import { regionDataPlus } from "static/js/regionData";
import PageList from "@/components/PageList";
import { mapGetters } from "vuex";
export default {
  name: "Arealist",
  components: {
    PageList
  },
  data() {
    return {
      // 表格数据
      listData: [],
      // 查询
      // searchForm: {
      //   siteName: ""
      // },
      roleEnum: [],
      // 分页
      totals: 0,
      currentPage: 1,
      pageSize: 15,
      inputs: 15,
      // loading
      loading: false
    };
  },
  mounted() {
    this.delectlist();
  },
  methods: {
    /**
     * 从后台获取人员列表
     * */
    getPeople() {
      let url = `${Config.DEVICE_MANAGE_URL}/device_modify_history/list`;
      let param = {
        page: this.currentPage - 1,
        size: this.pageSize,
        action_name: "delete_site",
        // site_name: this.searchForm.siteName
        //   ? this.searchForm.siteName
        //   : undefined
      };
      this.$http.get(url, param).then(res => {
        // console.log(res)
        res.array.forEach((item, i) => {
          if (this.dev_currentPage === 1) {
            item.num = i + 1;
          } else {
            item.num = (this.currentPage - 1) * this.pageSize + i + 1;
          }

          item.site_name = JSON.parse(item.old_data).site_name;
          item.address = JSON.parse(item.old_data).address;
          item.create_time = item.create_time? item.create_time.replace("T", " "): "";
          this.handleData(item);
        });
        this.totals = res.allcount;
        this.listData = res.array;
        this.loading = false;
      });
    },
    /**
     * 对展示数据进行预处理
     * */
    handleData(item) {
      const province = this.getAreaObj(
        regionDataPlus,
        JSON.parse(item.old_data).province
      );
      const city = this.getAreaObj(
        province.children,
        JSON.parse(item.old_data).city
      );
      const district = item.old_data.district
        ? this.getAreaObj(city.children, item.old_data.district)
        : { label: "" };
      item.areaName = `${province.label}${city.label}${district.label}`;
    },
    /**
     * 获取区域信息
     * @param {Array} arr
     * @param {String} value
     * @return {Object} obj
     * */
    getAreaObj(arr, value) {
      let obj = null;
      arr.some(item => {
        if (value === item.value) {
          obj = item;
          return true;
        }
      });
      return obj;
    },
    /**
     * 表头添加背景颜色
     * */
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background:#fafbfc";
      } else {
        return "";
      }
    },
    /**
     * 根据条件搜索搜索
     * */
    // search() {
    //   this.currentPage = 1;
    //   this.getPeople();
    // },
    // 删除限制数量
    delectlist() {
      let url = `${
        Config.DEVICE_MANAGE_URL
      }/device_modify_history/count_by_action_imei`;
      let param = {
        user_id: this.user.id,
        action_name: "delete_site"
      };
      this.$http.get(url, param).then(res => {
        if (res.count <= 20) {
          this.getPeople();
        } else {
          this.getPeople();
          this.$message({
            message: `主运营公司管理员：子运营公司管理员（${
              this.user.loginName
            }）删除了超过20个场所，请尽快联系对方！`,
            type: "error"
          });
        }
      });
    }
  },
  computed: {
    ...mapGetters("user", {
      district: "getDistrict",
      user: "getUser"
    })
  }
};
</script>

<!-- Add 'scoped' attribute to limit CSS to this component only -->
<style lang='scss' scoped>
@import "../../../../static/scss/common";
.newpeople {
  .el-input.is-disabled .el-input__inner {
    color: #606266;
    border: 0;
    background-color: #fff;
  }
  .el-row {
    padding: 0;
    .el-col {
      padding: 0 !important;
    }
  }
  .el-form {
    height: 110px;
    display: flex;
    align-items: center;
  }
  .el-form-item.img-name {
    font-family: "微软雅黑";
    font-size: 12px !important;
    font-weight: bold;
    color: #444;
    position: relative;
  }
  .el-form-item__label {
    font-size: 12px !important;
    padding: 0;
    text-align: left;
    text-indent: 51px;
  }
  .img-name /deep/ .el-form-item__label:before {
    position: absolute;
    display: block;
    left: 24px;
    top: 13px;
    content: " ";
    width: 15px;
    height: 20px;
    background: url("../../../../static/image/common/left.png") no-repeat;
  }
  .img-name /deep/ .el-form-item__label:after {
    position: absolute;
    display: block;
    left: 104px;
    top: 13px;
    content: " ";
    width: 20px;
    height: 20px;
    background: url("../../../../static/image/common/right.png") no-repeat;
  }
  .date-picker /deep/ .el-input--prefix .el-input__inner {
    padding-left: 30px;
  }
  .el-form-item.img-name {
    margin: 10px 0 10px 0;
  }
  .form .el-input__inner {
    height: 28px !important;
    line-height: 28px !important;
    border: 1px solid #e4e4e4;
    padding: 0 0 0 10px !important;
    .el-icon-time {
      line-height: 0;
    }
    .el-range-separator {
      line-height: 25px;
    }
  }
  .form.el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .poeple-list {
    width: 100%;
    height: auto;
    background: $white;
    margin-top: 20px;
    .add-user {
      height: 24px;
      line-height: 24px;
      margin-right: 27px;
      text-align: right;
      padding-top: 16px;
    }
    .pagination {
      padding: 32px 0 44px 23px;
      .page-left {
        font-size: 12px;
        display: inline-block;
        .el-input--suffix {
          width: 56px;
        }
      }
    }
  }
}
</style>
